﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/// <summary>
/// 分离力的策略
/// </summary>
public class SeparationStrategy : IStrategy
{
    public SeparationStrategy(Transform transform, float nearbyRadium, float forceWeight = 1) : base(transform, nearbyRadium, forceWeight) { }

    public override Vector3 GetForce()
    {
        Vector3 separationForce = Vector3.zero;

        //计算分离的力
        foreach (GameObject neighbor in mNearbyCrowList)
        {
            //个体产生的分离力
            Vector3 dir = mTransform.position - neighbor.transform.position;
            //综合各个分离力（随着距离越远产生的分离力越小）
            separationForce += dir.normalized / (dir.magnitude*10);
        }

        separationForce *= mForceWeight;

        return separationForce;
    }
}
